package org.jypj.dev.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.jypj.dev.util.StringUtil;
import org.springframework.stereotype.Service;
import org.jypj.dev.model.CommonMessage;
import org.jypj.dev.dao.ICommonMessageDao;
import org.jypj.dev.service.ICommonMessageService;
import org.jypj.dev.util.Page;
import org.jypj.dev.util.Page;

@Service("commonMessageService")
public class CommonMessageServiceImpl implements ICommonMessageService {

    @Resource
    private ICommonMessageDao commonMessageDao;

    /**
     * 保存
     * 所有字段全都保存
     *
     * @param commonMessage
     * @return 保存后的对象包括ID
     */
    public int saveCommonMessage(CommonMessage commonMessage) {
        if (StringUtil.isEmpty(commonMessage.getId())) {
            String uuid = UUID.randomUUID().toString().replace("-", "").trim();
            commonMessage.setId(uuid);
        }
        return commonMessageDao.saveCommonMessage(commonMessage);
    }

    /**
     * 根据ID删除
     *
     * @param id 主键ID
     * @return 删除记录数
     */
    public int deleteCommonMessageById(String id) {

        return commonMessageDao.deleteCommonMessageById(id);
    }

    /**
     * 根据对象删除
     *
     * @param commonMessage
     * @return
     */
    public int deleteCommonMessageByObject(CommonMessage commonMessage) {

        return commonMessageDao.deleteCommonMessageByObject(commonMessage);
    }

    /**
     * 更新
     * 更新所有字段
     *
     * @param commonMessage
     * @return 保存后的对象包括ID
     */
    public int updateCommonMessage(CommonMessage commonMessage) {

        return commonMessageDao.updateCommonMessage(commonMessage);
    }

    /**
     * 按ID查询
     *
     * @return CommonMessage
     * @parm id 主键ID
     */
    public CommonMessage selectCommonMessageById(String id) {

        return commonMessageDao.selectCommonMessageById(id);
    }

    /**
     * 分页查询 包含条件
     *
     * @param page 分页对象
     * @param map  查询条件
     * @return List<CommonMessage>
     */
    public Page selectOnePageByMap(Page page, Map<String, Object> map) {
        List<CommonMessage> commonMessages = commonMessageDao.selectOnePageByMap(page, map);
        if (commonMessages != null && commonMessages.size() > 0) {
            page.setResult(commonMessages);
        } else {
            page.setResult(new ArrayList<CommonMessage>());
        }
        return page;
    }

    /**
     * 分页查询 包含对象条件
     *
     * @param page          分页对象
     * @param commonMessage 查询条件
     * @return Page
     */
    public Page selectOnePageByCommonMessage(Page page, CommonMessage commonMessage) {
        List<CommonMessage> commonMessages = commonMessageDao.selectOnePageByCommonMessage(page, commonMessage);
        if (commonMessages != null && commonMessages.size() > 0) {
            page.setResult(commonMessages);
        } else {
            page.setResult(new ArrayList<CommonMessage>());
        }
        return page;
    }

    /**
     * 按条件查询全部的
     *
     * @param map 查询条件
     * @return List<CommonMessage>
     */
    public List<CommonMessage> selectAllByMap(Map<String, Object> map) {
        return commonMessageDao.selectAllByMap(map);
    }

    /**
     * 按条件查询全部的
     *
     * @param map 查询条件
     * @return List<CommonMessage>
     */
    public List<CommonMessage> selectAllByMap2(Map<String, Object> map) {
        return commonMessageDao.selectAllByMap2(map);
    }

    /**
     * 按条件查询全部的
     *
     * @param commonMessage 查询条件
     * @return List<CommonMessage>
     */
    public List<CommonMessage> selectAllByCommonMessage(CommonMessage commonMessage) {

        return commonMessageDao.selectAllByCommonMessage(commonMessage);
    }

    /**
     * 按条件查询单个对象
     *
     * @param map 查询条件
     * @return CommonMessage
     */
    public CommonMessage selectObjectByMap(Map<String, Object> map) {

        return commonMessageDao.selectObjectByMap(map);
    }

    /**
     * 按条件查询单个对象
     *
     * @param commonMessage 查询条件
     * @return CommonMessage
     */
    public CommonMessage selectObjectByCommonMessage(CommonMessage commonMessage) {

        return commonMessageDao.selectObjectByCommonMessage(commonMessage);
    }
}